<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/statics/layui/css/layui.css" media="all">
</head>

<body>

  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>我要卖</legend>
  </fieldset>
  <table class="layui-hide" id="dg" lay-filter="dg"></table>
  <script type="text/html" id="bar">
    <a class="layui-btn layui-btn-xs" lay-event="cell">卖出</a>
  </script>

  <script src="/statics/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="../js/jquery-1.11.0.min.js"></script>
  <script type="text/javascript" src="../js/config.js"></script>
  <script type="text/javascript" src="../js/utils.js"></script>
  <script>
    layui.use(['table', 'layer'], function () {
      var table = layui.table, layer = layui.layer;

      table.render({
        elem: '#dg',
        url: Config.WEB_SERVER_API + Config.URI.USER_MONEY_LIST,
        cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        cols: [[
          { field: 'typeName', title: '币种' },
          { field: 'money', title: '剩余数量' },
          { fixed: 'right', title: '操作', toolbar: '#bar', width: 150 }
        ]],
        page: false, loading: true,
        response: {
          statusCode: "200" //重新规定成功的状态码为 200，table 组件默认为 0
        },
        parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
          return {
            "code": parseInt(res.resultCode), //解析接口状态
            "msg": res.resultMsg, //解析提示文本
            "count": res.total, //解析数据长度
            "data": res.rows //解析数据列表
          };
        }
      });

      //监听行工具事件
      table.on('tool(dg)', function (obj) {
        var data = obj.data;
        if (obj.event === 'cell') {
          if (data.money == 0) {
            layer.alert('剩余数量不足，无法卖出！', { title: '出错了', icon: 5 });
          } else {
            var t = new Date().getTime();
            layer.open({
              type: 2
              , title: '我要卖'
              , offset: 'auto' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
              , area: ['400px', '320px']
              , id: 'layerDemo' //防止重复弹出
              , content: 'myselladd.html?t='+t+'&id=' + data.id
              , shade: 0.2 //不显示遮罩
              , yes: function () {
                layer.closeAll();
              }
            });
          }
        }
      });

    });
  </script>

</body>

</html>